//======================================================================================
//  Notes:Use this command to anonymously check out the latest project source code:
//  Non-members may check out a read-only working copy anonymously over HTTP.
//  http://YHQCodingWsp.googlecode.com/svn/trunk/
//
//  Author:		Kevin Yang
//  Email:		Bigearrabbit@qq.com
//
//  DATE:		2013-4-16
//
//  File Name:	YHQCodingDlg.cpp
//
//  Notes:
//
//======================================================================================

//Local
#include "YHQCodingDlg.h"
#include "ui_YHQCodingDlg.h"

//YHQCodingCore Library
#include "YHQPluginInterface.h"
#include "YHQCodingCore.h"

//Q_CORE Library
#include <QDir>
#include <QStringList>
#include <QPluginLoader>

//-----------------------------------------------------
YHQCodingDlg::YHQCodingDlg(QWidget *parent)
    : YHQMainWindow(parent)
    , ui(new Ui::YHQCodingDlg)
{
    ui->setupUi(this);
    YHQCodingCore::SetMainWindowPtr(this);
    ui->actionCAATools->setChecked(true);
    ui->actionOutPut->setChecked(true);
    ui->actionSvnTools->setChecked(true);
}
//-----------------------------------------------------
YHQCodingDlg::~YHQCodingDlg()
{
    delete ui;
}
//-----------------------------------------------------
void YHQCodingDlg::OutPutMessage(const QString & iString)
{
    this->ui->textEdit->append(iString);
}
//-----------------------------------------------------
QTextEdit *YHQCodingDlg::GetTextEditPtr()
{
    return ui->textEdit;//return edit pointer
}
//-----------------------------------------------------
void YHQCodingDlg::on_actionCAATools_triggered(bool checked)
{
    OutPutMessage("=====this action is moving to plugin. on working.=======");//message

    QDir pluginsDir ;
    QString fileName = "YHQCAATools.dll";// .pluginFileNames;
    QString DirPath = qApp->applicationDirPath();
    DirPath += "/Plugins";
    pluginsDir = QDir(DirPath);

    QString absoluteFilePath = pluginsDir.absoluteFilePath(fileName);
    OutPutMessage(absoluteFilePath);//message

    QPluginLoader loader(absoluteFilePath);
    QObject *plugin = loader.instance();
    if (plugin)
    {
        //OutPutMessage("--Load plugin OK!");//message
        //pluginFileNames += fileName;
        YHQPluginInterface *iBrush = qobject_cast<YHQPluginInterface *>(plugin);
        if (iBrush)
        {
            OutPutMessage("Get  YHQPluginInterface OK!");//message
            QString Errmsg;
            YHQDockWidget *pWidget = iBrush->LoadYHQDockWidget(&Errmsg);
            if(!pWidget)
            {
                OutPutMessage("YHQPluginInterface::LoadPlugin Faild!");//message
            }

        }
        else
        {
            OutPutMessage("Get  YHQPluginInterface Faild!");//message
        }

    }
    else
    {
        OutPutMessage("--Load plugin error!");//message
    }

}
//-----------------------------------------------------
void YHQCodingDlg::on_actionOutPut_triggered(bool arg1)
{
    ui->dockWidgetOutPut->setVisible(arg1);
}
//-----------------------------------------------------
void YHQCodingDlg::on_actionClear_Out_put_triggered()
{
    ui->textEdit->clear();//clear
}
//-----------------------------------------------------
void YHQCodingDlg::on_actionSvnTools_triggered(bool checked)
{
    OutPutMessage("=====this action is not realized.=======");//message
    YHQDockWidget  *  pdockWidget= new YHQDockWidget(this);//new dock widget
    this->addDockWidget(Qt::RightDockWidgetArea,pdockWidget);//add to main window
    pdockWidget->setWindowTitle("SVN Tools");//setWindowTitle
}
//-----------------------------------------------------
